package com.aries.crossgate.modules.sys.controller;

import com.aries.crossgate.common.log.config.Log;
import com.aries.crossgate.common.utils.Constant;
import com.aries.crossgate.common.utils.ShiroUtils;
import com.aries.crossgate.modules.sys.entity.SysMenu;
import com.aries.crossgate.modules.sys.entity.SysUser;
import com.aries.crossgate.modules.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @ProjectName: crossgate
 * @Package: com.aries.crossgate.modules.sys.controller
 * @ClassName: 首页面
 * @Description: java类作用描述
 * @Author: 李贝留斯
 * @CreateDate: 2018/5/7 17:34
 * @Version: 1.0
 **/
@Controller
public class SysIndexController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * TODO: 登录
     * @author 李贝留斯
     * @param
     * @date 2018/5/04 21:46
     */
    @Log("首页")
    @GetMapping(value = "/index.html")
    @ResponseBody
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView();
        SysUser sysUser = (SysUser) ShiroUtils.getSessionAttribute(Constant.SYSUSER);

        if(sysUser!=null){
            List<SysMenu> listMenu = sysMenuService.listMenuTree(sysUser.getUserId());
            //List<SysMenu> list = sysMenuService.selectSysMenuByUserId(sysUser.getUserId());
            modelAndView.addObject("menuList",listMenu);
            modelAndView.setViewName("index");
        }else{
            modelAndView.setViewName("redirect:login.html");
        }

        return modelAndView;
    }
}
